package handler

import (
	"github.com/mangenotwork/common/conf"
	"github.com/mangenotwork/common/ginHelper"
	"net/http/httputil"
	"net/url"
)

func Admin(c *ginHelper.GinCtx) {
	target, err := conf.YamlGetString("apiUrl")
	if err != nil {
		c.APIOutPutError(err, err.Error())
		return
	}

	proxyUrl, _ := url.Parse(target)
	c.Request.URL.Path = "/admin" + c.Param("url") //  重点是这行代码
	proxy := httputil.NewSingleHostReverseProxy(proxyUrl)
	proxy.ServeHTTP(c.Writer, c.Request)
}

func Ios(c *ginHelper.GinCtx) {
	target, err := conf.YamlGetString("apiUrl")
	if err != nil {
		c.APIOutPutError(err, err.Error())
		return
	}

	proxyUrl, _ := url.Parse(target)
	c.Request.URL.Path = "/ios" + c.Param("url") //  重点是这行代码
	proxy := httputil.NewSingleHostReverseProxy(proxyUrl)
	proxy.ServeHTTP(c.Writer, c.Request)
}
